const express = require('express');
const connection = require('../db') // 获取连接实例
const router = express.Router();

router.get('/getSkills', function(req, res, next) {
  // res.send('respond with a resource');
  let sql = "select * from skills";
  connection.query(sql,(err,result)=>{
    if(err){
      console.log(err);
      throw err;
    }else{
      //将数据转换为json格式
      const dataString = JSON.stringify(result);
      const data = JSON.parse(dataString);
      res.json({
        status:'0',
        errCode: 0,
        msg:data
      });
    }
  })
});
router.get('/getStudents', function(req, res, next) {
  // res.send('respond with a resource');
  let sql = "select * from student";
  connection.query(sql,(err,result)=>{
    if(err){
      throw err;
    }else{
      //将数据转换为json格式
      // const dataString = JSON.stringify(result);
      // const data = JSON.parse(dataString);
      res.send({
        status:'0',
        errCode: 0,
        msg:result
      });
    }
  })
});
module.exports = router;
